<?php

namespace App\Http\Traits;

use Barryvdh\DomPDF\Facade as PDF;
use Illuminate\Support\Facades\App;

trait ExportTrait
{
    /**
     * Export File as PDF
     *
     * @param string $viewName
     * @param array $data
     * @param string $paper
     * @param string $orientation
     * @return $this
     */
    public static function downloadPDF(string $viewName, array $data, 
        string $paper = 'A4', string $orientation = 'portrait'
    ) {
        $pdf = PDF::loadView($viewName, $data);
        $pdf->setPaper($paper, $orientation);
        return $pdf->download();
    }
}
